import * as DT from 'dt-sdk/library/DT'
//dtsdk等高线
/**
 * 增加等高线
 * @param { DT.Viewer} viewer 
 */
export function addContourLine(viewer){
    setTimeout(() => {
        var layers = [];
      var backgroundLayer = {
        entries: [
          
          {
            height: 1000.0,
            color: new DT.Cesium.Color(0.0, 0.0, 0.2, 0.1),
          },
          {
            height: 3000.0,
            color: new DT.Cesium.Color(0.0, 0.0, 0.2, 0.1),
          },
          {
            height: 4200.0,
            color: new DT.Cesium.Color(0.0, 0.0, 0.2, 0.1),
          },
          {
            height: 8000.0,
            color: new DT.Cesium.Color(1.0, 1.0, 1.0, 0.1),
          },
          {
            height: 8500.0,
            color: new DT.Cesium.Color(1.0, 0.0, 0.0, 0.1),
          },
        ],
        // extendDownwards: true,
        // extendUpwards: true,
      };
      layers.push(backgroundLayer);

      var gridStartHeight = 1000.0;
      var gridEndHeight = 8848.0;
      var gridCount = 100;
      for (var i = 0; i < gridCount; i++) {
        var lerper = i / (gridCount - 1);
        var heightBelow = DT.Cesium.Math.lerp(
          gridStartHeight,
          gridEndHeight,
          lerper
        );
        var heightAbove = heightBelow + 5.0;
        var alpha = 0.5
          // Cesium.Math.lerp(0.2, 0.4, lerper) * backgroundTransparency;
         
        layers.push({
          entries: [
            {
              height: heightBelow,
              color: new DT.Cesium.Color(1.0, 0.0, 0.0, 0.75),
            },
            {
              height: heightAbove,
              color: new DT.Cesium.Color(1.0, 0.0, 0.0, 0.75),
            },
          ],
        });
      }
      
        viewer.cesiumViewer.scene.globe.material = DT.Cesium.createElevationBandMaterial({
            scene : viewer.cesiumViewer.scene,
            layers : 
           layers
          //   [{
          //       entries : [{
          //           height : 4200.0,
          //           color : new DT.Cesium.Color(0.0, 0.0, 0.0, 0.75)
          //       }, {
          //           height : 8848.0,
          //           color : new DT.Cesium.Color(1.0, 1.0, 1.0, 0.75)
          //     }]
          //   }
          // ]
        });
      },5000)
}
/**
 * 移除等高线
 * @param { DT.Viewer} viewer 
 */
export function removeContourLine(viewer){
    viewer.cesiumViewer.scene.globe.material= undefined
}
